<template>
  <div id="login">
    <el-card header="任务管理系统">
      <el-form :model="model" ref="loginRef">
        <el-form-item label="用户名">
          <el-input v-model="model.username" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="model.password" @keyup.enter.native="onSubmit" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">登录</el-button>
          <el-button @click="resetForm()">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      model: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    // 登录
    async onSubmit() {
      const res = await this.$http.post('/login',this.model)
      window.localStorage.token = res.data.token
      window.localStorage.admin = res.data.adminuser.username
      window.localStorage._id = res.data.adminuser._id
      this.$router.push('/')
      this.$message({
        type:'success',
        message:'登录成功'
      })
    },
    // 重置
    resetForm() {
      this.$refs.loginRef.resetFields();
      this.model = {
          name:'',
          password:''
      }
    },

    hhh(){
      
    }
  },
};
</script>

<style lang="less" scoped>
#login {
  height: 100vh;
  background-color: #26154e;
  display: grid;
  place-items: center;
  .el-card {
    width: 28rem;
  }
}
</style>